//
// Created by gxx on 2023/11/11.
//
#ifndef TINY_DB_MEMORY_POOL_H
#define TINY_DB_MEMORY_POOL_H

#include "util/base_types.h"
#include <vector>
#include <cassert>

namespace TinyDB{

const static t_int32 kBlockSize = 4096;

class MemoryPool {
 public:
  MemoryPool();
  ~MemoryPool();

  MemoryPool(const MemoryPool&)            = delete;
  MemoryPool& operator=(const MemoryPool&) = delete;

	t_byte* Allocate(t_uint64 size);
	t_byte* AllocateAlign(t_uint64 size);

 private:
	t_byte* allocateFallback(t_uint64 size);
  t_byte* allocateNewBlock(t_uint64 size);

  t_byte* alloc_ptr_;
  t_uint64 byte_remaining_;
  std::vector<t_byte*> blocks_;
};

}

#endif //TINY_DB_MEMORY_POOL_H
